/*
 * Copyright (c) 2010 by Aleksey Zhukov
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

package ru.listfunc4j;

import org.junit.Test;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import static ru.listfunc4j.ListFunction.forEach;

/**
 * User: J0k3r
 * Date: 20.11.2010
 * Time: 14:18:04
 */
public class TimingTest {
    @Test
    public void timingTest() throws Exception {
        List< SimpleBean > myList = new LinkedList<SimpleBean>();
        Random random = new Random();
        for (int nI = 0; nI < 100000; ++nI)
            myList.add(new SimpleBean(Integer.toString(random.nextInt(100000))));
        long start = System.currentTimeMillis();
        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
//        for (SimpleBean simpleBean : myList) simpleBean.setS("Test!");
        System.out.println("Time elapsed: " + (System.currentTimeMillis() - start));
        start = System.currentTimeMillis();
        forEach(myList).
                of(SimpleBean.class).setS("Test");
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }}).
//                add(new Updater<SimpleBean>() {{ $.setS("Test"); _ = $; }});
        System.out.println("Time elapsed: " + (System.currentTimeMillis() - start));
    }
}
